package demoMod.stsconsole.helpers;

import demoMod.stsconsole.ConsoleEntry;
import demoMod.stsconsole.interfaces.ReloadStringsSubscriber;
import demoMod.stsconsole.monsters.ApologySlime;
import demoMod.stsconsole.monsters.exordium.*;
import demoMod.stsconsole.rooms.AbstractRoom;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

public class MonsterHelper implements ReloadStringsSubscriber {
    private static final Map<String, Consumer<AbstractRoom>> encounters = new HashMap<>();
    private static final Map<String, String> encounterNames = new HashMap<>();

    public MonsterHelper() {
        ConsoleEntry.subscribers.add(this);
        onReloadStrings();
    }

    public static void initialize() {
        encounters.clear();
        encounters.put("JawWorm", room -> room.monsters.monsters.add(new JawWorm(false)));
        encounters.put("2 Slime_1", room -> {
            room.monsters.monsters.add(new AcidSlime_S());
            room.monsters.monsters.add(new SpikeSlime_M());
        });
        encounters.put("2 Slime_2", room -> {
            room.monsters.monsters.add(new SpikeSlime_S());
            room.monsters.monsters.add(new AcidSlime_M());
        });
        encounters.put("2 Louse_1", room -> {
            room.monsters.monsters.add(new LouseNormal());
            room.monsters.monsters.add(new LouseDefensive());
        });
        encounters.put("2 Louse_2", room -> {
            room.monsters.monsters.add(new LouseNormal());
            room.monsters.monsters.add(new LouseNormal());
        });
        encounters.put("2 Louse_3", room -> {
            room.monsters.monsters.add(new LouseDefensive());
            room.monsters.monsters.add(new LouseDefensive());
        });
        encounters.put("Cultist", room -> room.monsters.monsters.add(new Cultist()));
        encounters.put("AcidSlime_L", room -> room.monsters.monsters.add(new AcidSlime_L()));
        encounters.put("SpikeSlime_L", room -> room.monsters.monsters.add(new SpikeSlime_L()));
        encounters.put("Lots of slimes", room -> {
            room.monsters.monsters.add(new AcidSlime_S());
            room.monsters.monsters.add(new SpikeSlime_S());
            room.monsters.monsters.add(new AcidSlime_S());
            room.monsters.monsters.add(new SpikeSlime_S());
            room.monsters.monsters.add(new AcidSlime_S());
        });
        encounters.put("JawWorm with slime_1", room -> {
            room.monsters.monsters.add(new JawWorm(false));
            room.monsters.monsters.add(new AcidSlime_M());
        });
        encounters.put("JawWorm with slime_2", room -> {
            room.monsters.monsters.add(new JawWorm(false));
            room.monsters.monsters.add(new SpikeSlime_M());
        });
        encounters.put("Cultist with slime_1", room -> {
            room.monsters.monsters.add(new Cultist());
            room.monsters.monsters.add(new AcidSlime_M());
        });
        encounters.put("Cultist with slime_2", room -> {
            room.monsters.monsters.add(new Cultist());
            room.monsters.monsters.add(new SpikeSlime_M());
        });
        encounters.put("3 Louse_1", room -> {
            room.monsters.monsters.add(new LouseNormal());
            room.monsters.monsters.add(new LouseDefensive());
            room.monsters.monsters.add(new LouseNormal());
        });
        encounters.put("3 Louse_2", room -> {
            room.monsters.monsters.add(new LouseDefensive());
            room.monsters.monsters.add(new LouseNormal());
            room.monsters.monsters.add(new LouseDefensive());
        });
        encounters.put("2 Mushrooms", room -> {
            room.monsters.monsters.add(new FungiBeast());
            room.monsters.monsters.add(new FungiBeast());
        });
        encounters.put("3 Mushrooms", room -> {
            room.monsters.monsters.add(new FungiBeast());
            room.monsters.monsters.add(new FungiBeast());
            room.monsters.monsters.add(new FungiBeast());
        });
        encounters.put("Lagavulin", room -> room.monsters.monsters.add(new Lagavulin(true)));
        encounters.put("GremlinNob", room -> room.monsters.monsters.add(new GremlinNob()));
        encounters.put("3 Sentries", room -> {
            room.monsters.monsters.add(new Sentry(true));
            room.monsters.monsters.add(new Sentry(false));
            room.monsters.monsters.add(new Sentry(true));
        });
    }

    public static void getEncounter(String encounterId, AbstractRoom room) {
        encounters.getOrDefault(encounterId, abstractRoom -> abstractRoom.monsters.monsters.add(new ApologySlime())).accept(room);
    }

    public static String getEncounterNameById(String encounterId) {
        return encounterNames.getOrDefault(encounterId, encounterNames.get("ApologySlime"));
    }

    @Override
    public void onReloadStrings() {
        List<String> uiStrings = LocalizedStrings.getUIStrings("MonsterHelper");
        encounterNames.clear();
        encounterNames.put("JawWorm", uiStrings.get(0));
        encounterNames.put("ApologySlime", uiStrings.get(1));
        encounterNames.put("2 Slime_1", uiStrings.get(2));
        encounterNames.put("2 Slime_2", uiStrings.get(3));
        encounterNames.put("2 Louse_1", uiStrings.get(4));
        encounterNames.put("2 Louse_2", uiStrings.get(5));
        encounterNames.put("2 Louse_3", uiStrings.get(6));
        encounterNames.put("Cultist", uiStrings.get(7));
        encounterNames.put("AcidSlime_L", uiStrings.get(8));
        encounterNames.put("SpikeSlime_L", uiStrings.get(9));
        encounterNames.put("Lots of slimes", uiStrings.get(10));
        encounterNames.put("JawWorm with slime_1", uiStrings.get(11));
        encounterNames.put("JawWorm with slime_2", uiStrings.get(12));
        encounterNames.put("Cultist with slime_1", uiStrings.get(13));
        encounterNames.put("Cultist with slime_2", uiStrings.get(14));
        encounterNames.put("3 Louse_1", uiStrings.get(15));
        encounterNames.put("3 Louse_2", uiStrings.get(16));
        encounterNames.put("SlimeBoss", uiStrings.get(17));
        encounterNames.put("Hexaghost", uiStrings.get(18));
        encounterNames.put("TheGuardian", uiStrings.get(19));
        encounterNames.put("2 Mushrooms", uiStrings.get(20));
        encounterNames.put("3 Mushrooms", uiStrings.get(21));
        encounterNames.put("Lagavulin", uiStrings.get(22));
        encounterNames.put("GremlinNob", uiStrings.get(23));
        encounterNames.put("3 Sentries", uiStrings.get(24));
    }
}
